package com.example.Service.Impl;

import com.example.Mapper.CourseMapper;
import com.example.Mapper.Stu_CourMapper;
import com.example.Pojo.Course;
import com.example.Pojo.PageQuery;
import com.example.Service.CourseService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;
    @Autowired
    private Stu_CourMapper stu_courMapper;
    @Override
    public PageQuery<Course> list(Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<Course> coursePage=courseMapper.list();
        Page<Course> page1=(Page<Course>) coursePage;
        return new PageQuery<>((int) page1.getTotal(),page1.getResult());
    }

    @Override
    public void addCourse(Course course) {
        courseMapper.addCourse(course);
    }

    @Override
    public void deleteCourse(Integer id) {
        courseMapper.deleteCourse(id);
        stu_courMapper.deleteByCouId(id);
    }

    @Override
    public void updateCourse(Course course) {
        courseMapper.updateCourse(course);
    }
}
